package com.summer.dingding.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.summer.core.util.LocalConstants;
import com.summer.dingding.model.DingDingMessageTemplate;
import com.summer.dingding.service.DingDingMessageService;

@Service("dingDingMessageService")
public class DingDingMessageServiceImpl implements DingDingMessageService{

	public DingDingMessageTemplate buildSendMessage(String jumpUrl, String title, String content, String author, String image, List<Map<String, String>> form) {
		
		DingDingMessageTemplate message = new DingDingMessageTemplate();
		message.setMessage_url(jumpUrl);
		message.getBody().setContent(content);
		message.getBody().setTitle(title);
		message.getBody().setAuthor(author);
		message.getBody().setImage(image);
		if(form != null && form.size() > 0) {
			for (int i = 0; i < form.size(); i++) {
				if(form.get(i) != null) {
					Map<String, String> form1 = new HashMap<String, String>();
					form1.put("key", form.get(i).get("key"));
					form1.put("value", form.get(i).get("value"));
					message.getBody().getForm().add(form1);
				}
			}
		}
		return message;
	}
}
